from flask import Flask
from flask import render_template
from flask import request
from flask import jsonify
import json
from flask_cors import *
from db_client import *
from login import *
from store import *
from get import *
from search import *
from update import *

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
CORS(app, resources=r'/*', supports_credentials=True)


@app.route('/', methods = ['GET'])
def Index():
    return render_template('hello.html')

# api -1
@app.route('/api/login', methods = ['POST'])
def login():
    result = login_func.login()
    #print(result)
    return result

# api -2
@app.route('/api/store/demand', methods = ['POST'])
def store_demand():
    result = None
    try:
        result = store_demand_func.store_demand()
    except Exception as e:        
        result = store_error_func.store_error(e)
    
    return result

# api -3
@app.route('/api/store/plan', methods = ['POST'])
def store_plan():
    result = store_plan_func.store_plan()
    return result

# api -4
@app.route('/api/store/order', methods = ['POST'])
def store_order():
    result = store_order_func.store_order()
    return result

# api -5
@app.route('/api/store/entry', methods = ['POST'])
def store_entry():
    result = store_entry_func.store_entry()
    return result

# api -6
@app.route('/api/store/receive', methods = ['POST'])
def store_receive():
    result = store_receive_file_func.store_receive_file()
    #print('store_receive_file')
    return result

# api -7
@app.route('/api/store/demand_file', methods = ['POST'])
def store_demand_file():
    result = store_demand_file_func.store_demand_file()
    return result

# api -8
@app.route('/api/store/contract_file', methods = ['POST'])
def store_contract_file():
    result = store_contract_file_func.store_contract_file()
    return result

# api -9
@app.route('/api/store/order_file', methods = ['POST'])
def store_order_file():
    result = store_order_file_func.store_order_file()
    return result

# api -10
@app.route('/api/get/demand/', methods = ['GET'])
def get_demand():
    demand_list = get_demand_func.get_demand()
    return jsonify(demand_list)



#api -11
@app.route('/api/get/plan', methods = ['GET'])
def get_plan():
    result = get_plan_func.get_plan()
    return result
    
#api -12
@app.route('/api/get/order', methods = ['GET'])
def get_order():
    result = get_order_func.get_order()
    return result

#api -13
@app.route('/api/get/entry', methods = ['GET'])
def get_entry():
    result = get_entry_func.get_entry()
    return result

#api -15
@app.route('/api/get/demand_file', methods = ['GET'])
def get_demand_file():
    result = get_demand_file_func.get_demand_file()
    return result

@app.route('/api/get/demand_files', methods = ['GET'])
def get_demand_files():
    result = get_demand_file_func.get_demand_files()
    return result

# api -16
@app.route('/api/get/contract_file', methods = ['GET'])
def get_contract_file():
    result = get_contract_file_func.get_contract_file()
    return result

#api -17
@app.route('/api/get/order_file', methods = ['GET'])
def get_order_file():
    result = get_order_file_func.get_order_file()
    return result

#api -18
@app.route('/api/get/receive_file', methods = ['GET'])
def get_take_file():
    result = get_receive_file_func.get_receive_file()
    return result

#api -19
@app.route('/api/get/item', methods = ['GET'])
def get_item():
    result = get_item_func.get_item()
    return result

#api -20
@app.route('/api/get/supplier', methods = ['GET'])
def get_supplier():
    result = get_supplier_func.get_supplier()
    return result

#api -21
@app.route('/api/get/supplier-select', methods = ['GET'])
def get_supplier_select():
    result = get_supplier_select_func.get_supplier_select()
    return result

#api -22
@app.route('/api/search/current_staff', methods = ['GET'])
def search_staff():
    result = search_staff_func.search_staff()
    return result

#api -23
@app.route('/api/update/supplier', methods = ['POST'])
def update_supplier():
    result = update_supplier_func.update_supplier()
    return result
#api -24
@app.route('/api/update/item', methods = ['POST'])
def update_item():
    result = update_item_func.update_item()
    return result
#api -25
@app.route('/api/update/current_staff', methods = ['POST'])
def update_staff():
    result = update_staff_func.update_staff()
    return result
#api -26
@app.route('/api/update/demand', methods = ['POST'])
def update_demand():
    result = update_demand_func.update_demand()
    return result
#api -27
@app.route('/api/update/plan', methods = ['POST'])
def update_paln():
    result = update_plan_func.update_paln()
    return result
#api -28
@app.route('/api/add/item', methods = ['POST'])
def store_item():
    result = store_item_func.store_item()
    return result
    

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)

